package com.xiaochong.tir.apiservice.component;

import akka.actor.UntypedActor;
import com.xc.logclient.utils.LogTrace;
import com.xiaochong.tir.apiservice.util.SpringContextUtil;
import com.xiaochong.tir.common.data.hbasepo.CmcCurrencyInfo;
import com.xiaochong.tir.common.data.hbasepo.DiagnosisAverageCost;
import com.xiaochong.tir.common.util.LogTraceKeysUtils;

import java.util.List;
import java.util.Map;

/**
 * Created by wujiaxing on 2018/5/7.
 */
public class AkkaDiagnosisAverageCost extends UntypedActor {


    private CmcDataCalculateComponent cmcDataCalculateComponent =
            (CmcDataCalculateComponent) SpringContextUtil.getBean("cmcDataCalculateComponent");

    @Override
    public void onReceive(Object o) {
        LogTrace.beginTrace("平均成本计算");
        Object o1 = ((Object[]) o)[0];
        //List<CmcCurrencyInfo> cmcCurrencyInfos = (List<CmcCurrencyInfo>) o1;
        Map<String, CmcCurrencyInfo> cmcInfoMap = (Map<String, CmcCurrencyInfo>) o1;
        LogTrace.info(LogTraceKeysUtils.AKKA_DIAGNOSIS_AVERAGE_COST_TITLE, LogTraceKeysUtils.DATA,"平均成本计算开始");
        try{
            List<DiagnosisAverageCost> diagnosisAverageCosts = cmcDataCalculateComponent.calculateDiagnosisAverageCost(cmcInfoMap, null);
            LogTrace.info(LogTraceKeysUtils.AKKA_DIAGNOSIS_AVERAGE_COST_TITLE, LogTraceKeysUtils.DATA, "平均成本计算完成");
            if(diagnosisAverageCosts!=null && diagnosisAverageCosts.size()>0){
                cmcDataCalculateComponent.saveDiagnosisAverageCost(diagnosisAverageCosts);
            }
        }catch (Exception e){
            e.printStackTrace();
            LogTrace.error(e.getMessage(), e);
        }

        LogTrace.endTrace();
    }
}
